package com.qf.gh.service.impl;

import com.qf.gh.dao.GoodsDao;
import com.qf.gh.dao.impl.GoodsDaoImpl;
import com.qf.gh.domain.Goods;
import com.qf.gh.domain.GoodsType;
import com.qf.gh.domain.PageBean;
import com.qf.gh.service.GoodsService;
import com.qf.gh.service.GoodsTypeService;

import java.util.List;

public class GoodaServiceImpl implements GoodsService {
    GoodsDao goodsDao=new GoodsDaoImpl();
    @Override
    public PageBean findByPage(int typeId, int pageNum, int pageSize) {
        PageBean pageBean=new PageBean();
        pageBean.setPageNum(pageNum);
        pageBean.setPageSize(pageSize);
        long totalCount = goodsDao.findTotalCount(typeId);
        pageBean.setTotalCount(totalCount);
        List<Goods> list = goodsDao.findData(typeId, (pageNum - 1) * pageSize , pageSize);
        pageBean.setData(list);

        return pageBean;
    }

    @Override
    public Goods findById(int id) {
        Goods goods=goodsDao.selectById(id);
        GoodsTypeService typeService = new GoodsTypeServiceImpl();
        GoodsType goodsType = typeService.selectById(goods.getTypeid());
        goods.setGoodsType(goodsType);
        return goods;
    }

    @Override
    public List<Goods> find() {
        return goodsDao.select();
    }

    @Override
    public void insert(Goods goods) {
        goodsDao.add(goods);
    }

    @Override
    public void delete(int parseInt) {
        goodsDao.delete(parseInt);
    }

    @Override
    public void update(Goods goods,int i) {
        goodsDao.update(goods,i);
    }

    @Override
    public List<Goods> findByName(String toString, List<Object> parmas) {
        return goodsDao.find(toString,parmas);
    }
}
